package didi.hcp.provider.service;

import didi.hcp.api.HelloService;
import didi.hcp.api.SayGoodbyeService;
import didi.hcp.provider.annotation.NeedUser;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.annotation.Service;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.beans.factory.annotation.Autowired;

@Service(version = "1.0.0")
public class HelloServiceImpl implements HelloService, INeedUser {

    @Autowired
    AnotherServiceImpl anotherService;

    @Reference(version = "1.0.0",check = false)
    SayGoodbyeService sayGoodbyeService;

    @NeedUser
    @Override
    public String sayHello(String str) {
        System.out.println("Provider | str="+str);
        System.out.println("远程调用前：");
        String name = RpcContext.getContext().getAttachment("name");
        System.out.println("HelloServiceImpl | name="+name);
        test();
        anotherService.test2();
        String byebye = sayGoodbyeService.sayGoodBye("byebye");
        System.out.println(byebye);
        System.out.println("远程调用后：");
        anotherService.test2();
        return "Provider " + str;
    }

    public void test(){
        System.out.println("Test | "+get());
    }
}
